home *** CD-ROM | disk | FTP | other *** search
-
- #include <hfs.h>
- #include "ssghfslib.h"
-
- main()
- {
- char name[100];
- int ref, res;
- int dir;
-
- do
- {
- scanf ("%s %d", name, &dir);
- res = file_exists (name, -2, dir, &ref);
- printf ("\nresult=%d ref=%d", res, ref);
- }
- while ( name[1] != '`' );
-
- }
-
- /*
- file_exists: tests to see if a file exists
-
- Passed:
- char *name; file/folder name - C string
- int the_vol; vRefNum, wdRefNum, or 0 for current
- int the_dir; dirRefnum, 0 for current of if WD specified
- int *ref; returns dirRefNum if is dir and exists (can pass 0L)
-
- Returns:
- int 1=file exists, 2=folder exists, 0=no exist, -1=I/O err
- */
- file_exists (name, the_vol, the_dir, ref)
- unsigned char *name;
- int the_vol;
- int the_dir;
- int *ref;
- {
- CInfoPBRec pb;
- unsigned char temp[50];
- int error;
-
- CtoPstr ( name);
- pb.dirInfo.ioCompletion = 0L;
- pb.dirInfo.ioFDirIndex = 0;
- pb.dirInfo.ioNamePtr = name;
- pb.dirInfo.ioVRefNum = the_vol;
- pb.dirInfo.ioDrDirID = the_dir;
-
- error = PBGetCatInfo (&pb, FALSE);
- switch ( error )
- {
- case noErr:
- if ( pb.dirInfo.ioFlAttrib & HFS_DIR ) /* dir? */
- {
- if ( ref )
- *ref = pb.dirInfo.ioDrDirID;
- return ( 2 );
- }
- else
- return ( 1 );
- case fnfErr:
- return (0);
- default:
- return (-1);
- }
- }
-
-
-